#include <stdlib.h>

#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int K; // K is the number of pancakes
string generate_pancake_rule(int d);

string convertInt(int number)
{
   ostringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
      cout << "provide K as an argument please." <<endl;
      return -1;
    }

    K=atoi(argv[1]);
    
    string havij;

    havij=havij+convertInt(K)+"\n";
    havij = havij + "\n";
 
    for (int i=0;i<K;i++)
        havij=havij+convertInt(K)+" ";
    havij = havij + "\n";
    havij=havij+"\n";
   
    for (int d=1; d<K; d++)
    {
        havij=havij+generate_pancake_rule(d);
    }
    havij = havij + "\n";
    havij = havij + "\n";
    havij=havij+"GOAL ";
    for (int i=0;i<K;i++)
    {
        havij=havij+ convertInt(i)+" ";
    }
    havij=havij+"\n";
    cout << havij;

    return (EXIT_SUCCESS);
}


string generate_pancake_rule(int d)
{
    string tstr1="";
    string tstr2="";
    for (int i=0; i<=d; i++)
    {
        tstr1=tstr1+"A"+convertInt(i)+" ";
        tstr2=tstr2+"A"+convertInt(d-i)+" ";
    }
    for (int i=d+1; i<K; i++)
    {
        tstr1=tstr1+"- ";
        tstr2=tstr2+"- ";
    }
    tstr1=tstr1+"=> "+tstr2;
    tstr1=tstr1+"LABEL FLIP_top"+convertInt(d+1)+"\n";
    return tstr1;
}

/* 
 * Original file created by Meysam Bastani
 * Edited by: Shahab Jabbari
 * This file generated PSVN file for K-pancake puzzle
*/
